<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Register</title>
    <style>
        .wrap{
            text-align: center;
        }
        h1{
            text-align: center;
        }
        input{
            margin-bottom: 16px;
        }
    </style>
</head>
<body>
<div class="wrap">
    <h1>注册页面</h1>
    昵称 <input type="text" name="nickname"><br>
    密码 <input type="password" name="password"><br>
    确认密码 <input type="password" name="QPassword">
    <div class="btn">
        <button id="register">注册</button>
    </div>
</div>
<script src="/public/js/jquery-3.3.1.min.js"></script>
<script>
    let register = $('#register')

    register.click(() => {
        let nickname = $('input[name="nickname"]').val()
        let pass = $('input[name="password"]').val()
        let pass2 = $('input[name="QPassword"]').val()
        if (pass !== pass2) {
            alert('密码输入不一致，请重新输入')
        } else {
            let params = {username: nickname, pass}
            $.ajax({
                url: '/post/register',
                type: 'POST',
                data: JSON.stringify(params),
                headers: {'Content-Type': 'application/json'},
                success: (res) => {
                    console.log(res)
                }
            })
        }
    })
</script>
</body>
</html>